package com.gilly;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("*.do")
public class FrontControllerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String requestURI = request.getRequestURI();
		String contextPath = request.getContextPath();
		String command = requestURI.substring(contextPath.length());

		if (command.equals("/Insert.do")) {
			String id = request.getParameter("id");
			String password = request.getParameter("password");
			String name = request.getParameter("name");
			String address = request.getParameter("address");
			String email = request.getParameter("email");
			String phone1 = request.getParameter("phone1");
			String phone2 = request.getParameter("phone2");
			String phone3 = request.getParameter("phone3");
			PrintWriter out = response.getWriter();

			ArrayList<MemberDTO> list = new ArrayList<MemberDTO>();
			InsertService insert = new InsertService();
			insert.execute(id, password, name, address, email, phone1, phone2,
					phone3);

			response.sendRedirect("main.html");
		} else if(command.equals("/login.do")){
			request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			String id = request.getParameter("id");
			String password = request.getParameter("password");
			//속성설정
			request.setAttribute("id", id);
			request.setAttribute("password", password);
			
			//forward
			RequestDispatcher dis = request.getRequestDispatcher("LoginService");
		
			dis.forward(request, response);
		}else if (command.equals("/delete.do")) {
			System.out.println("delete");
		} else if (command.equals("/update.do")) {
			System.out.println("update");
		} else {
			System.out.println("select");
		}
	}

}
